package com.info.game;


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.component.game.RenderComponent;
import com.engine.game.GameFabric;
import com.engine.game.GameObject;
import com.engine.game.MessageInfo;

public class LabelRenderComponent implements RenderComponent{

	
	private Sprite sprite;
	
	

	public LabelRenderComponent(){
		
		this.sprite = GameFabric.createSprite("Nothing.png");
		
		float y = (2.0f/5)*Gdx.graphics.getHeight();
		float width = (1.0f/4)*Gdx.graphics.getWidth();
		float height = (1.0f/5)*Gdx.graphics.getHeight();
		
		this.sprite.setBounds(0.0f, y, width, height);
	}
	

	
	@Override
	public void dispose() {
		this.sprite.getTexture().dispose();
		
	}

	@Override
	public void update(GameObject object) {
		
		 for(MessageInfo message : object.getRenderMessages()){
			 
			 if(message.message.contains("needed")){
				 
				 String[] parts = message.message.split(";");
				 
				 this.chooseSprite(parts[1]);
			 }
		 }
		
		
	}
	
	public void chooseSprite(String name){
		
		if(name.equals("win")){
			this.sprite = GameFabric.createSprite("Win.png");
		}
		else if(name.equals("lose")){
			this.sprite = GameFabric.createSprite("Lose.png");
		}
		
		float y = (2.0f/5)*Gdx.graphics.getHeight();
		float width = (1.0f/4)*Gdx.graphics.getWidth();
		float height = (1.0f/5)*Gdx.graphics.getHeight();
		
		this.sprite.setBounds(0.0f, y, width, height);
		
	}

	@Override
	public Sprite getSprite() {
		
		return this.sprite;
	}

}
